package com.lagou.springbootredis.factory;

import com.lagou.springbootredis.cache.RedisAutoConfiguration;
import org.springframework.beans.factory.annotation.Value;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

public class JedisClusterFactory {

    private static class RedisUtilHolder {
        private static final JedisClusterFactory instance = new JedisClusterFactory();
    }

    public static JedisClusterFactory getInstance() {
        return RedisUtilHolder.instance;
    }

    public JedisCluster getJedisCluster() {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(800);
        config.setMaxIdle(200);
        config.setMaxWaitMillis(3000);
        config.setMinIdle(50);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);

        JedisCluster cluster = new JedisCluster(RedisAutoConfiguration.NODES, config);
        return cluster;
    }

}
